#include<iostream>
using namespace std;
#include<ctime>
#include<cstdio>

#include "set.h"




int main(){
	srand(time(0));
	char op;
	while( cin >> op ){
		if( op == 'X' )
			break;
		
		Set s1, s2, s3;
		int card1, card2, card3;
		
		cin >> card1;
		for(int i = 0; i < card1; ++i){
			int v;
			cin >> v;
			s1.insert(v);
		}
		
		cin >> card2;
		for(int i = 0; i < card2; ++i){
			int v;
			cin >> v;
			s2.insert(v);
		}
		
		cin >> card3;
		for(int i = 0; i < card3; ++i){
			int v;
			cin >> v;
			s3.insert(v);
		}
		
		if( op == 'E' ){
			Set temps1, temps2;
			temps1 = s1;
			temps2 = s2;
			
			cout << Set::intersection(&s1,&s2)->equals(&s3) << " "; Set::intersection(&s1,&s2)->print();
			cout << Set::intersection(&s2,&s1)->equals(&s3) << " "; Set::intersection(&s2,&s1)->print();
			(s1.intersection(&temps2)); cout << s1.equals(&s3) << " "; s1.print();
			(s2.intersection(&temps1)); cout << s2.equals(&s3) << " "; s2.print();
			cout << endl;
		}
		else if( op == 'U' ){
			Set temps1, temps2;
			temps1 = s1;
			temps2 = s2;
			
			cout << Set::union_(&s1,&s2)->equals(&s3) << " "; Set::union_(&s1,&s2)->print();
			cout << Set::union_(&s2,&s1)->equals(&s3) << " "; Set::union_(&s2,&s1)->print();
			(s1.union_(&temps2)); cout << s1.equals(&s3) << " "; s1.print();
			(s2.union_(&temps1)); cout << s2.equals(&s3) << " "; s2.print();
			cout << endl;
		}
	}
	
	
	
}